<!--
	作者：2575202388@qq.com
	时间：2018-10-14
	描述：Checkbox 全选框
-->
<template>
	<Checkbox :indeterminate="cData.indeterminate" :value="cData.checkAll" @click.stop.native="handleCheckAll">{{label}}</Checkbox>
</template>

<script>
	export default {
		name: "ParentCheckbox",
		props: {
			cData: {
				type: Object,
				default: function() {
					return {};
				}
			},
			label: {
				type: String,
				default: function() {
					return "全选";
				}
			}
		},
		data() {
			return {}
		},
		methods: {
			handleCheckAll() {
				if(this.cData.indeterminate) {
					this.cData.checkAll = false;
					this.cData.indeterminate = false;
				} else {
					this.cData.checkAll = !this.cData.checkAll;
				}
				if(this.cData.checkAll) {
					this.cData.checkedkeys = this.getAllKeys();
				} else {
					this.cData.checkedkeys = [];
				}
			},
			getAllKeys() {

				const _data = [];
				this.cData.datas.forEach((value) => {
					const _v = value[(this.cData.keyname)];
					if(_v) {
						_data.push(_v);
					}

				})
				return _data;
			}
		}
	}
</script>

<style scoped="scoped">

</style>